package com.yami.shop.live.api.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.param.LiveRoomParam;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.live.common.dto.LiveRoomDto;
import com.yami.shop.live.common.service.LiveRoomService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;


/**
 * @author lhd
 * @date 2020-08-05 08:53:17
 */
@RestController
@RequestMapping("/live/liveRoom" )
@Tag(name = "直播接口")
public class LiveRoomController {

    @Autowired
    private LiveRoomService liveRoomService;

    @GetMapping("/page" )
    @Operation(summary =  "直播间列表信息", description = "直播间列表信息")
    public ServerResponseEntity<IPage<LiveRoomDto>> getLiveRoomPage(PageParam<LiveRoomDto> page,@ParameterObject LiveRoomParam liveRoomParam){
        // 如果type为空，则为搜索直播信息
        if(Objects.isNull(liveRoomParam.getSearchType())||StrUtil.isBlank(liveRoomParam.getName())){
            liveRoomParam.setSearchType(1);
            liveRoomParam.setName("");
        }
        liveRoomParam.setRoomTop(0);
        return ServerResponseEntity.success(liveRoomService.pageRoomAndDetail(page,liveRoomParam));
    }

    @GetMapping("/pageTopRoom" )
    @Operation(summary =  "置顶直播间列表信息", description = "置顶直播间列表信息")
    public ServerResponseEntity<IPage<LiveRoomDto>> getLiveRoomPageByTop(PageParam<LiveRoomDto> page){
        LiveRoomParam liveRoom = new LiveRoomParam();
        liveRoom.setRoomTop(1);
        liveRoom.setSearchType(1);
        liveRoom.setName("");
        return ServerResponseEntity.success(liveRoomService.pageRoomAndDetail(page,liveRoom));
    }
}
